package cn.iocoder.yudao.module.wine.dal.mysql.supplyorder;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.wine.controller.app.supplyinfo.enums.SupplyInfoEnum;
import cn.iocoder.yudao.module.wine.controller.app.supplyorder.enums.SupplyOrderEnum;
import cn.iocoder.yudao.module.wine.controller.app.supplyorder.vo.AppSupplyOrderListReqVO;
import cn.iocoder.yudao.module.wine.controller.app.supplyorder.vo.AppSupplyOrderRespVO;
import cn.iocoder.yudao.module.wine.dal.dataobject.businesscredit.BusinessCreditDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.businessuser.BusinessUserDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.membertype.MemberTypeDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyorder.SupplyOrderDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.wine.controller.admin.supplyorder.vo.*;

/**
 * 供求订单管理 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface SupplyOrderMapper extends BaseMapperX<SupplyOrderDO> {

    default PageResult<SupplyOrderDO> selectPage(SupplyOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SupplyOrderDO>()
                .eqIfPresent(SupplyOrderDO::getNo, reqVO.getNo())
                .eqIfPresent(SupplyOrderDO::getType, reqVO.getType())
                .eqIfPresent(SupplyOrderDO::getSaleUserId, reqVO.getSaleUserId())
                .eqIfPresent(SupplyOrderDO::getBuyUserId, reqVO.getBuyUserId())
                .eqIfPresent(SupplyOrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(SupplyOrderDO::getTradeType, reqVO.getTradeType())
                .eqIfPresent(SupplyOrderDO::getPayOrderId, reqVO.getPayOrderId())
                .eqIfPresent(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(SupplyOrderDO::getPayTime, reqVO.getPayTime())
                .betweenIfPresent(SupplyOrderDO::getFinishTime, reqVO.getFinishTime())
                .eqIfPresent(SupplyOrderDO::getPremiumStatus, reqVO.getPremiumStatus())
                .betweenIfPresent(SupplyOrderDO::getCreateTime, reqVO.getCreateTime())
                .ne(SupplyOrderDO::getStatus, SupplyOrderEnum.CANCEL.getCode())
                .orderByDesc(SupplyOrderDO::getId));
    }

    default PageResult<SupplyOrderRespVO> selectNewPage(SupplyOrderPageReqVO reqVO) {
        return selectJoinPage(reqVO,SupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                .eqIfPresent(SupplyOrderDO::getNo, reqVO.getNo())
                .eqIfPresent(SupplyOrderDO::getType, reqVO.getType())
                .eqIfPresent(SupplyOrderDO::getSaleUserId, reqVO.getSaleUserId())
                .eqIfPresent(SupplyOrderDO::getBuyUserId, reqVO.getBuyUserId())
                .eqIfPresent(SupplyOrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(SupplyOrderDO::getTradeType, reqVO.getTradeType())
                .eqIfPresent(SupplyOrderDO::getPayOrderId, reqVO.getPayOrderId())
                .eqIfPresent(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(SupplyOrderDO::getPayTime, reqVO.getPayTime())
                .betweenIfPresent(SupplyOrderDO::getFinishTime, reqVO.getFinishTime())
                .eqIfPresent(SupplyOrderDO::getPremiumStatus, reqVO.getPremiumStatus())
                .betweenIfPresent(SupplyOrderDO::getCreateTime, reqVO.getCreateTime())
                .ne(SupplyOrderDO::getStatus, SupplyOrderEnum.CANCEL.getCode())
                .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                .selectAll(SupplyOrderDO.class)
                .selectAs("buy1", MemberUserDO::getName, SupplyOrderRespVO::getBuyUserName)
                .selectAs("sale1", MemberUserDO::getName, SupplyOrderRespVO::getSaleUserName)
                .orderByDesc(SupplyOrderDO::getId));
    }

    /**
     * 正常交易、担责交易、担责担保交易
     * @param integers
     * @param reqVO
     * @return
     */
    default List<AppSupplyOrderRespVO> selectListItem2(List<Integer> integers, AppSupplyOrderListReqVO reqVO) {
        if (SupplyOrderEnum.AFTER_SALE.getCode().equals(reqVO.getStatus())) {
            if (SupplyInfoEnum.SELL.getCode().equals(reqVO.getType())) {
                return selectJoinList(AppSupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                        .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                        .eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                        .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                        //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                        .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                        .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId())
                        .in(SupplyOrderDO::getStatus,
                                SupplyOrderEnum.AFTER_SALE.getCode(),  SupplyOrderEnum.COMPLETED.getCode(),
                                SupplyOrderEnum.REMITTED_MONEY_STATUS.getCode(),  SupplyOrderEnum.UNDER_RETURN_APPLICATION.getCode(),
                                SupplyOrderEnum.RETURNING_GOODS.getCode(), SupplyOrderEnum.RETURNED.getCode())
                        .or(wrapper -> {
                                    wrapper.eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                            .eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                                            .eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                                            .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                            //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                            .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                            .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId())
                                            .in(SupplyOrderDO::getStatus,
                                                    SupplyOrderEnum.AFTER_SALE.getCode(), SupplyOrderEnum.COMPLETED.getCode(),
                                                    SupplyOrderEnum.REMITTED_MONEY_STATUS.getCode(), SupplyOrderEnum.UNDER_RETURN_APPLICATION.getCode(),
                                                    SupplyOrderEnum.RETURNING_GOODS.getCode(), SupplyOrderEnum.RETURNED.getCode());
                                }
                        )
                        .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                        .leftJoin(BusinessUserDO.class, "buy2", BusinessUserDO::getUserId, SupplyOrderDO::getBuyUserId)
                        .leftJoin(BusinessCreditDO.class, "buy3", BusinessCreditDO::getId, "buy2", BusinessUserDO::getCreditId)
                        .leftJoin(MemberTypeDO.class, "buy4", MemberTypeDO::getId, "buy2", BusinessUserDO::getMemberTypeId)

                        .selectAs("buy1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getBuyNickname)
                        .selectAs("buy1", MemberUserDO::getName, AppSupplyOrderRespVO::getBuyName)
                        .selectAs("buy1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getBuyAvatar)
                        .selectAs("buy2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getBuyAreaId)
                        .selectAs("buy2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getBuyCompanyName)
                        .selectAs("buy2", BusinessUserDO::getReceiveAddress, AppSupplyOrderRespVO::getBuyReceiveAddress)
                        .selectAs("buy2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getBuyBondName)
                        .selectAs("buy3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getBuyIcon)
                        .selectAs("buy3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getBuyCreditId)
                        .selectAs("buy3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getBuyCreditName)
                        .selectAs("buy4", MemberTypeDO::getName, AppSupplyOrderRespVO::getBuyMemberTypeName)
                        .selectAs("buy4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getBuyMemberTypeIcon)
                        .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                        .leftJoin(BusinessUserDO.class, "sale2", BusinessUserDO::getUserId, SupplyOrderDO::getSaleUserId)
                        .leftJoin(BusinessCreditDO.class, "sale3", BusinessCreditDO::getId, "sale2", BusinessUserDO::getCreditId)
                        .leftJoin(MemberTypeDO.class, "sale4", MemberTypeDO::getId, "sale2", BusinessUserDO::getMemberTypeId)
                        .selectAll(SupplyOrderDO.class)

                        .selectAs("sale1", MemberUserDO::getName, AppSupplyOrderRespVO::getSaleName)
                        .selectAs("sale1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getSaleNickname)
                        .selectAs("sale1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getSaleAvatar)
                        .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                        .selectAs("sale2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getSaleAreaId)
                        .selectAs("sale2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getSaleCompanyName)
                        .selectAs("sale2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getSaleDeliveryAddress)
                        .selectAs("sale2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getSaleBondName)
                        .selectAs("sale3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getSaleIcon)
                        .selectAs("sale3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getSaleCreditId)
                        .selectAs("sale3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getSaleCreditName)
                        .selectAs("sale4", MemberTypeDO::getName, AppSupplyOrderRespVO::getSaleMemberTypeName)
                        .selectAs("sale4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getSaleMemberTypeIcon)
                        .orderByDesc(SupplyOrderDO::getId));
            }
            if (SupplyInfoEnum.ASK_TO_BUY.getCode().equals(reqVO.getType())) {
                return selectJoinList(AppSupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                        .eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                        .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                        .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                        //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                        .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                        .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId())
                        .in(SupplyOrderDO::getStatus,
                                SupplyOrderEnum.AFTER_SALE.getCode(), SupplyOrderEnum.COMPLETED.getCode(),
                                SupplyOrderEnum.REMITTED_MONEY_STATUS.getCode(), SupplyOrderEnum.UNDER_RETURN_APPLICATION.getCode(),
                                SupplyOrderEnum.RETURNING_GOODS.getCode(), SupplyOrderEnum.RETURNED.getCode())
                        .or(wrapper -> {
                                    wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                                            .eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                                            .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                            .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                            //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                            .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                            .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId())
                                            .in(SupplyOrderDO::getStatus,
                                                    SupplyOrderEnum.AFTER_SALE.getCode(), SupplyOrderEnum.COMPLETED.getCode(),
                                                    SupplyOrderEnum.REMITTED_MONEY_STATUS.getCode(), SupplyOrderEnum.UNDER_RETURN_APPLICATION.getCode(),
                                                    SupplyOrderEnum.RETURNING_GOODS.getCode(), SupplyOrderEnum.RETURNED.getCode());
                                }
                        )
                        .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                        .leftJoin(BusinessUserDO.class, "buy2", BusinessUserDO::getUserId, SupplyOrderDO::getBuyUserId)
                        .leftJoin(BusinessCreditDO.class, "buy3", BusinessCreditDO::getId, "buy2", BusinessUserDO::getCreditId)
                        .leftJoin(MemberTypeDO.class, "buy4", MemberTypeDO::getId, "buy2", BusinessUserDO::getMemberTypeId)

                        .selectAs("buy1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getBuyNickname)
                        .selectAs("buy1", MemberUserDO::getName, AppSupplyOrderRespVO::getBuyName)
                        .selectAs("buy1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getBuyAvatar)
                        .selectAs("buy2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getBuyAreaId)
                        .selectAs("buy2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getBuyCompanyName)
                        .selectAs("buy2", BusinessUserDO::getReceiveAddress, AppSupplyOrderRespVO::getBuyReceiveAddress)
                        .selectAs("buy2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getBuyBondName)
                        .selectAs("buy3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getBuyIcon)
                        .selectAs("buy3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getBuyCreditId)
                        .selectAs("buy3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getBuyCreditName)
                        .selectAs("buy4", MemberTypeDO::getName, AppSupplyOrderRespVO::getBuyMemberTypeName)
                        .selectAs("buy4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getBuyMemberTypeIcon)

                        .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                        .leftJoin(BusinessUserDO.class, "sale2", BusinessUserDO::getUserId, SupplyOrderDO::getSaleUserId)
                        .leftJoin(BusinessCreditDO.class, "sale3", BusinessCreditDO::getId, "sale2", BusinessUserDO::getCreditId)
                        .leftJoin(MemberTypeDO.class, "sale4", MemberTypeDO::getId, "sale2", BusinessUserDO::getMemberTypeId)
                        .selectAll(SupplyOrderDO.class)

                        .selectAs("sale1", MemberUserDO::getName, AppSupplyOrderRespVO::getSaleName)
                        .selectAs("sale1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getSaleNickname)
                        .selectAs("sale1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getSaleAvatar)
                        .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                        .selectAs("sale2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getSaleAreaId)
                        .selectAs("sale2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getSaleCompanyName)
                        .selectAs("sale2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getSaleDeliveryAddress)
                        .selectAs("sale2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getSaleBondName)
                        .selectAs("sale3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getSaleIcon)
                        .selectAs("sale3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getSaleCreditId)
                        .selectAs("sale3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getSaleCreditName)
                        .selectAs("sale4", MemberTypeDO::getName, AppSupplyOrderRespVO::getSaleMemberTypeName)
                        .selectAs("sale4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getSaleMemberTypeIcon)
                        .orderByDesc(SupplyOrderDO::getId));
            }
            return selectJoinList(AppSupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                    .eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                    .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                    .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus())
                    .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                    .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                    //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                    .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                    .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId())
                    .or(wrapper -> {
                        wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                                .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                                .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus())
                                .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId());
                    })
                    .or(wrapper -> {
                                wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                                        .eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                                        .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                                        .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus())
                                        .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                        .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                        //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                        .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                        .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId());
                            }
                    )
                    .or(wrapper -> {
                                wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                                        .eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                                        .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                                        .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus())
                                        .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                        .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                        //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                        .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                        .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId());
                            }
                    )
                    .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                    .leftJoin(BusinessUserDO.class, "buy2", BusinessUserDO::getUserId, SupplyOrderDO::getBuyUserId)
                    .leftJoin(BusinessCreditDO.class, "buy3", BusinessCreditDO::getId, "buy2", BusinessUserDO::getCreditId)
                    .leftJoin(MemberTypeDO.class, "buy4", MemberTypeDO::getId, "buy2", BusinessUserDO::getMemberTypeId)

                    .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                    .leftJoin(BusinessUserDO.class, "sale2", BusinessUserDO::getUserId, SupplyOrderDO::getSaleUserId)
                    .leftJoin(BusinessCreditDO.class, "sale3", BusinessCreditDO::getId, "sale2", BusinessUserDO::getCreditId)
                    .leftJoin(MemberTypeDO.class, "sale4", MemberTypeDO::getId, "sale2", BusinessUserDO::getMemberTypeId)
                    .selectAll(SupplyOrderDO.class)

                    .selectAs("buy1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getBuyNickname)
                    .selectAs("buy1", MemberUserDO::getName, AppSupplyOrderRespVO::getBuyName)
                    .selectAs("buy1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getBuyAvatar)
                    .selectAs("buy2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getBuyAreaId)
                    .selectAs("buy2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getBuyCompanyName)
                    .selectAs("buy2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getBuyReceiveAddress)
                    .selectAs("buy2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getBuyBondName)
                    .selectAs("buy3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getBuyIcon)
                    .selectAs("buy3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getBuyCreditId)
                    .selectAs("buy3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getBuyCreditName)
                    .selectAs("buy4", MemberTypeDO::getName, AppSupplyOrderRespVO::getBuyMemberTypeName)
                    .selectAs("buy4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getBuyMemberTypeIcon)

                    .selectAs("sale1", MemberUserDO::getName, AppSupplyOrderRespVO::getSaleName)
                    .selectAs("sale1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getSaleNickname)
                    .selectAs("sale1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getSaleAvatar)
                    .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                    .selectAs("sale2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getSaleAreaId)
                    .selectAs("sale2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getSaleCompanyName)
                    .selectAs("sale2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getSaleDeliveryAddress)
                    .selectAs("sale2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getSaleBondName)
                    .selectAs("sale3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getSaleIcon)
                    .selectAs("sale3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getSaleCreditId)
                    .selectAs("sale3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getSaleCreditName)
                    .selectAs("sale4", MemberTypeDO::getName, AppSupplyOrderRespVO::getSaleMemberTypeName)
                    .selectAs("sale4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getSaleMemberTypeIcon)

                    .orderByDesc(SupplyOrderDO::getId));
        } else {
            if (SupplyInfoEnum.SELL.getCode().equals(reqVO.getType())) {
                return selectSELLItemList(reqVO);
            }
            if (SupplyInfoEnum.ASK_TO_BUY.getCode().equals(reqVO.getType())) {
                return  selectBUYItemList(reqVO);
            }
        }
        return selectItemList(reqVO);
    }


    default AppSupplyOrderRespVO getAppSupplyOrder(Long id) {
        return selectJoinOne(AppSupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                .eqIfExists(SupplyOrderDO::getId, id)
                .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessUserDO.class, "buy2", BusinessUserDO::getUserId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessCreditDO.class, "buy3", BusinessCreditDO::getId, "buy2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "buy4", MemberTypeDO::getId, "buy2", BusinessUserDO::getMemberTypeId)

                .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessUserDO.class, "sale2", BusinessUserDO::getUserId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessCreditDO.class, "sale3", BusinessCreditDO::getId, "sale2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "sale4", MemberTypeDO::getId, "sale2", BusinessUserDO::getMemberTypeId)
                .selectAll(SupplyOrderDO.class)
                .selectAs("buy1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getBuyNickname)
                .selectAs("buy1", MemberUserDO::getName, AppSupplyOrderRespVO::getBuyName)
                .selectAs("buy1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getBuyAvatar)
                .selectAs("buy2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getBuyAreaId)
                .selectAs("buy2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getBuyCompanyName)
                .selectAs("buy2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getBuyReceiveAddress)
                .selectAs("buy2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getBuyBondName)
                .selectAs("buy3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getBuyIcon)
                .selectAs("buy3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getBuyCreditId)
                .selectAs("buy3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getBuyCreditName)
                //.selectAs("buy4", MemberTypeDO::getName, AppSupplyOrderRespVO::getBuyMemberTypeName)
                //.selectAs("buy4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getBuyMemberTypeIcon)

                .selectAs("sale1", MemberUserDO::getName, AppSupplyOrderRespVO::getSaleName)
                .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                .selectAs("sale1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getSaleNickname)
                .selectAs("sale1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getSaleAvatar)
                .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                .selectAs("sale2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getSaleCompanyName)
                .selectAs("sale2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getSaleAreaId)
                .selectAs("sale2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getSaleDeliveryAddress)
                .selectAs("sale2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getSaleBondName)
                .selectAs("sale3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getSaleIcon)
                .selectAs("sale3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getSaleCreditId)
                .selectAs("sale3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getSaleCreditName)
                //.selectAs("sale4", MemberTypeDO::getName, AppSupplyOrderRespVO::getSaleMemberTypeName)
                //.selectAs("sale4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getSaleMemberTypeIcon)
        );
    }


    default List<AppSupplyOrderRespVO> selectSELLItemList(AppSupplyOrderListReqVO reqVO) {
        return selectJoinList(AppSupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                .eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId())
                .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus())
                .or(wrapper -> {
                            wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                                    .eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                                    .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                    .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                    //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                    .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                    .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId())
                                    .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus());
                        }
                )
                .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessUserDO.class, "buy2", BusinessUserDO::getUserId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessCreditDO.class, "buy3", BusinessCreditDO::getId, "buy2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "buy4", MemberTypeDO::getId, "buy2", BusinessUserDO::getMemberTypeId)

                .selectAs("buy1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getBuyNickname)
                .selectAs("buy1", MemberUserDO::getName, AppSupplyOrderRespVO::getBuyName)
                .selectAs("buy1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getBuyAvatar)
                .selectAs("buy2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getBuyAreaId)
                .selectAs("buy2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getBuyCompanyName)
                .selectAs("buy2", BusinessUserDO::getReceiveAddress, AppSupplyOrderRespVO::getBuyReceiveAddress)
                .selectAs("buy2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getBuyBondName)
                .selectAs("buy3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getBuyIcon)
                .selectAs("buy3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getBuyCreditId)
                .selectAs("buy3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getBuyCreditName)
                //.selectAs("buy4", MemberTypeDO::getName, AppSupplyOrderRespVO::getBuyMemberTypeName)
                //.selectAs("buy4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getBuyMemberTypeIcon)

                .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessUserDO.class, "sale2", BusinessUserDO::getUserId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessCreditDO.class, "sale3", BusinessCreditDO::getId, "sale2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "sale4", MemberTypeDO::getId, "sale2", BusinessUserDO::getMemberTypeId)
                .selectAll(SupplyOrderDO.class)

                .selectAs("sale1", MemberUserDO::getName, AppSupplyOrderRespVO::getSaleName)
                .selectAs("sale1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getSaleNickname)
                .selectAs("sale1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getSaleAvatar)
                .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                .selectAs("sale2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getSaleAreaId)
                .selectAs("sale2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getSaleCompanyName)
                .selectAs("sale2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getSaleDeliveryAddress)
                .selectAs("sale2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getSaleBondName)
                .selectAs("sale3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getSaleIcon)
                .selectAs("sale3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getSaleCreditId)
                .selectAs("sale3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getSaleCreditName)
                //.selectAs("sale4", MemberTypeDO::getName, AppSupplyOrderRespVO::getSaleMemberTypeName)
                //.selectAs("sale4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getSaleMemberTypeIcon)
                .orderByDesc(SupplyOrderDO::getId));
    }

    default List<AppSupplyOrderRespVO> selectBUYItemList(AppSupplyOrderListReqVO reqVO) {
        return selectJoinList(AppSupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                .eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId())
                .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus())
                .or(wrapper -> {
                            wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                                    .eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                                    .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                    .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                    //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                    .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                    .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId())
                                    .eqIfExists(SupplyOrderDO::getStatus, reqVO.getStatus());
                        }
                )
                .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessUserDO.class, "buy2", BusinessUserDO::getUserId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessCreditDO.class, "buy3", BusinessCreditDO::getId, "buy2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "buy4", MemberTypeDO::getId, "buy2", BusinessUserDO::getMemberTypeId)

                .selectAs("buy1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getBuyNickname)
                .selectAs("buy1", MemberUserDO::getName, AppSupplyOrderRespVO::getBuyName)
                .selectAs("buy1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getBuyAvatar)
                .selectAs("buy2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getBuyAreaId)
                .selectAs("buy2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getBuyCompanyName)
                .selectAs("buy2", BusinessUserDO::getReceiveAddress, AppSupplyOrderRespVO::getBuyReceiveAddress)
                .selectAs("buy2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getBuyBondName)
                .selectAs("buy3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getBuyIcon)
                .selectAs("buy3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getBuyCreditId)
                .selectAs("buy3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getBuyCreditName)
                //.selectAs("buy4", MemberTypeDO::getName, AppSupplyOrderRespVO::getBuyMemberTypeName)
                //.selectAs("buy4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getBuyMemberTypeIcon)

                .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessUserDO.class, "sale2", BusinessUserDO::getUserId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessCreditDO.class, "sale3", BusinessCreditDO::getId, "sale2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "sale4", MemberTypeDO::getId, "sale2", BusinessUserDO::getMemberTypeId)
                .selectAll(SupplyOrderDO.class)

                .selectAs("sale1", MemberUserDO::getName, AppSupplyOrderRespVO::getSaleName)
                .selectAs("sale1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getSaleNickname)
                .selectAs("sale1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getSaleAvatar)
                .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                .selectAs("sale2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getSaleAreaId)
                .selectAs("sale2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getSaleCompanyName)
                .selectAs("sale2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getSaleDeliveryAddress)
                .selectAs("sale2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getSaleBondName)
                .selectAs("sale3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getSaleIcon)
                .selectAs("sale3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getSaleCreditId)
                .selectAs("sale3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getSaleCreditName)
                //.selectAs("sale4", MemberTypeDO::getName, AppSupplyOrderRespVO::getSaleMemberTypeName)
                //.selectAs("sale4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getSaleMemberTypeIcon)
                .orderByDesc(SupplyOrderDO::getId));
    }

    default List<AppSupplyOrderRespVO> selectItemList(AppSupplyOrderListReqVO reqVO) {
        return selectJoinList(AppSupplyOrderRespVO.class, new MPJLambdaWrapperX<SupplyOrderDO>()
                .eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                .ne(SupplyOrderDO::getStatus, SupplyOrderEnum.CANCEL.getCode())
                .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId())
                .or(wrapper -> {
                            wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                                    //.eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                                    .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                                    .ne(SupplyOrderDO::getStatus, SupplyOrderEnum.CANCEL.getCode())
                                    .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                                    .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                                    //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                                    .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                                    .eqIfExists(SupplyOrderDO::getBuyUserId, SecurityFrameworkUtils.getLoginUserId());
                        }
                )
                .or(wrapper -> {
                    wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY.getCode())
                            .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                            .ne(SupplyOrderDO::getStatus, SupplyOrderEnum.CANCEL.getCode())
                            .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                            .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                            //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                            .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                            .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId());
                })
                .or(wrapper -> {
                    wrapper.eqIfExists(SupplyOrderDO::getTradeType, SupplyOrderEnum.TAKE_RESPONSIBILITY_GUARANTEE.getCode())
                            //.eqIfExists(SupplyOrderDO::getAffirmDuty, SupplyOrderEnum.NOT_AFFIRM_DUTY.getCode())
                            .eqIfExists(SupplyOrderDO::getType, reqVO.getType())
                            .ne(SupplyOrderDO::getStatus, SupplyOrderEnum.CANCEL.getCode())
                            .eqIfExists(SupplyOrderDO::getCancelType, reqVO.getCancelType())
                            .eqIfExists(SupplyOrderDO::getPayStatus, reqVO.getPayStatus())
                            //.eqIfExists(SupplyOrderDO::getDeliveryType, reqVO.getDeliveryType())
                            .eqIfExists(SupplyOrderDO::getOperateStatus, reqVO.getOperateStatus())
                            .eqIfExists(SupplyOrderDO::getSaleUserId, SecurityFrameworkUtils.getLoginUserId());
                })
                .leftJoin(MemberUserDO.class, "buy1", MemberUserDO::getId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessUserDO.class, "buy2", BusinessUserDO::getUserId, SupplyOrderDO::getBuyUserId)
                .leftJoin(BusinessCreditDO.class, "buy3", BusinessCreditDO::getId, "buy2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "buy4", MemberTypeDO::getId, "buy2", BusinessUserDO::getMemberTypeId)

                .leftJoin(MemberUserDO.class, "sale1", MemberUserDO::getId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessUserDO.class, "sale2", BusinessUserDO::getUserId, SupplyOrderDO::getSaleUserId)
                .leftJoin(BusinessCreditDO.class, "sale3", BusinessCreditDO::getId, "sale2", BusinessUserDO::getCreditId)
                //.leftJoin(MemberTypeDO.class, "sale4", MemberTypeDO::getId, "sale2", BusinessUserDO::getMemberTypeId)
                .selectAll(SupplyOrderDO.class)

                .selectAs("buy1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getBuyNickname)
                .selectAs("buy1", MemberUserDO::getName, AppSupplyOrderRespVO::getBuyName)
                .selectAs("buy1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getBuyAvatar)
                .selectAs("buy2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getBuyAreaId)
                .selectAs("buy2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getBuyCompanyName)
                .selectAs("buy2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getBuyReceiveAddress)
                .selectAs("buy2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getBuyBondName)
                .selectAs("buy3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getBuyIcon)
                .selectAs("buy3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getBuyCreditId)
                .selectAs("buy3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getBuyCreditName)
                //.selectAs("buy4", MemberTypeDO::getName, AppSupplyOrderRespVO::getBuyMemberTypeName)
                //.selectAs("buy4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getBuyMemberTypeIcon)

                .selectAs("sale1", MemberUserDO::getName, AppSupplyOrderRespVO::getSaleName)
                .selectAs("sale1", MemberUserDO::getNickname, AppSupplyOrderRespVO::getSaleNickname)
                .selectAs("sale1", MemberUserDO::getAvatar, AppSupplyOrderRespVO::getSaleAvatar)
                .selectAs("sale1", MemberUserDO::getMobile, AppSupplyOrderRespVO::getSaleMobile)
                .selectAs("sale2", BusinessUserDO::getAreaId, AppSupplyOrderRespVO::getSaleAreaId)
                .selectAs("sale2", BusinessUserDO::getCompanyName, AppSupplyOrderRespVO::getSaleCompanyName)
                .selectAs("sale2", BusinessUserDO::getDeliveryAddress, AppSupplyOrderRespVO::getSaleDeliveryAddress)
                .selectAs("sale2", BusinessUserDO::getBondName, AppSupplyOrderRespVO::getSaleBondName)
                .selectAs("sale3", BusinessCreditDO::getIcon, AppSupplyOrderRespVO::getSaleIcon)
                .selectAs("sale3", BusinessCreditDO::getId, AppSupplyOrderRespVO::getSaleCreditId)
                .selectAs("sale3", BusinessCreditDO::getName, AppSupplyOrderRespVO::getSaleCreditName)
                //.selectAs("sale4", MemberTypeDO::getName, AppSupplyOrderRespVO::getSaleMemberTypeName)
                //.selectAs("sale4", MemberTypeDO::getIcon, AppSupplyOrderRespVO::getSaleMemberTypeIcon)
                .orderByDesc(SupplyOrderDO::getId));
    }
}